var manageTeacherCtrl = myApp.controller('manageTeacherCtrl', ['$scope', '$rootScope', 'NgTableParams', function($scope, $rootScope, NgTableParams) {
	$rootScope.firstType = Tools.permissionList[4].permissionId;
	$rootScope.secondType = Tools.permissionList[4].sonPermission[1].permissionId;
	
	$scope.newTeaItem = {};
	$scope.modTeaItem = {};
	$scope.delTeaItem = {};

	// 提示弹层
	$scope.msg = "";
	$scope.visible = false;

	// 分页 
	$scope.pageList = [];
	$scope.curPage = 1;
	$scope.totalPage = 1;
	$scope.totalRow = 0;
	var PAGESIZE = 10;

	/**
	 * 获取教师列表
	 * @param  {[type]} curPage [当前页面]
	 */
	$scope.getTeacherList = function (curPage) {
		var data = {
			curPage: curPage,
			pagesize: PAGESIZE
		};
		commonSrv.getTeacherList(data, function(result) {
			var list = result.data;
			$scope.teacherList = new NgTableParams({count: PAGESIZE}, { counts: [],  dataset: list});
			var paginate = result.paginate;
			$scope.totalPage = paginate.totalPage;
			$scope.totalRow = paginate.totalRow;
			$scope.setPage(curPage);
		}, function(result) {
			if(result.status == 1) {
				$scope.msg = result.msg;
				$scope.visible = true;
			}
		}, function() {
			$scope.$apply();
		});
	};

	// 设置分页
	$scope.setPage = function(curPage) {
		var newPageList = [];
		if (curPage < 1 || curPage > $scope.totalPage) {
			alert("设置分页失败");
			return;
		}
		var SHOWSIZE = 5;
		// 总页数小于SHOWSIZE
		if($scope.totalPage <= SHOWSIZE) {
			for(var i=0; i<$scope.totalPage; i++) {
				newPageList.push(i+1);
			}
		// 总页数大于等于SHOWSIZE
		} else {
			if(curPage > 2) {
				// 最后5页
				if(($scope.totalPage - curPage) < 2) {
					for(var i = ($scope.totalPage - 5); i < $scope.totalPage; i++) {
						newPageList.push(i + 1);
					}
				} else {
					for (var i = (curPage - 3); i < ((curPage + 2) > $scope.totalPage ? $scope.totalPage : (curPage + 2)); i++) {
                        newPageList.push(i + 1);
                    }
				}
			} else {
				for(var i=0; i<SHOWSIZE; i++) {
					newPageList.push(i + 1);
				}
			}
		}
        $scope.pageList = newPageList;
        $scope.curPage = curPage;
	};

	//设置当前选中页样式
    $scope.isActivePage = function (page) {
        return $scope.curPage == page;
    };
    //上一页
    $scope.previous = function () {
        if($scope.curPage > 1) {
        	$scope.getTeacherList($scope.curPage - 1);
        }
    }
    //下一页
    $scope.next = function () {
        if($scope.curPage < $scope.totalPage) {
        	$scope.getTeacherList($scope.curPage + 1);
        }
    };

    // 新增
    /**
     * 打开新增教师弹层
     */
    $scope.openAdd = function() {
    	var data = {};
    	commonSrv.getTeacherAddForm(data, function(result) {
    		if(result.status == 0) {
    			var data = result.data;
    			$scope.newTeaItem = angular.copy(data);
    			$scope.newTeaItem.name = "";
    			$scope.newTeaItem.code = "";
    			$scope.newTeaItem.joinedDate = "";
    			$scope.newTeaItem.tel = "";
    			$scope.newTeaItem.mobile = "";
    			$scope.newTeaItem.email = "";
    			$scope.newTeaItem.birthday = "";
    			$scope.newTeaItem.school = "";
    			$scope.newTeaItem.contact = "";
    			$scope.newTeaItem.contactTel = "";
    			$scope.newTeaItem.address = "";
    			$scope.newTeaItem.homeTel = "";
    			$scope.newTeaItem.homePostcode = "";
    			$.ajax({
    				// url: '/ta/CityCtrl/getAllCity.do',
    				url: '../common/libs/allCity.json',
    				data: {},
    				success: function(result) {
    					if (typeof result == 'string') {
    						result = JSON.parse(result);
    					}
    					// 省市区
    					$scope.allCity = result;
    					var provinceList = [];
    					for(var i in $scope.allCity) {
    						provinceList.push(i);
    					}
    					$scope.newTeaItem.provinceList = provinceList;
    					$scope.newTeaItem.cityList = [];
    					$scope.newTeaItem.districtList = [];
    					
    					// 生日日期
						$("#birthday").datepicker({
							format: "yyyy-mm-dd",
							language: 'zh-CN'
						});
						// 入职日期
						$("#joinedDate").datepicker({
							format: "yyyy-mm-dd",
							language: 'zh-CN'
						});

		    			// 已选择
		    			$scope.newTeaItem.select = {
		    				title: "",
		    				userId: {},
		    				status: $scope.newTeaItem.statusList[0],
		    				sex: {},
		    				countryId: {},
		    				maritalStatus: {},
		    				education: {},
		    				province: "",
		    				city: "",
		    				district: ""
		    			};
		    			// 警告
		    			$scope.newTeaItem.warn = {
		    				address: "",
							birthday: "",
							code: "",
							contact: "",
							contactTel: "",
							countryId: "",
							education: "",
							email: "",
							homePostcode: "",
							homeTel: "",
							joinedDate: "",
							maritalStatus: "",
							mobile: "",
							name: "",
							school: "",
							sex: "",
							status: "",
							tel: "",
							title: "",
							userId: ""
		    			};
		    			console.log("newTeaItem", $scope.newTeaItem);
    					$("#addTeaModel").modal({backdrop: 'static', keyboard: false, show: true});
    				},
	    			fail: function(result) {
	    				if(result.status == 1) {
	    					alert("获取城市下拉列表失败");
	    				}
	    			}
	    		}).always(function() {
	    			$scope.$apply();
	    		})
    		}
    	}, function(result) {
    		if(result.status == 1) {
    			alert(result.msg);
    		}
    	}, function() {
    		$scope.$apply();
    	});
    };
    // 打开日期插件
	$scope.openDate = function(target) {
		var $myDatePicker = $(target).parents('.input-group').children('.myDatePicker');
		$myDatePicker.datepicker('show');
	};
	// 清除日期值
	$scope.cleanDate = function(target) {
		var $myDatePicker = $(target).parents('.input-group').children('.myDatePicker');
		$myDatePicker.datepicker('update', '');
	};
	// 选择省份
	$scope.selectProvince = function(type) {
		var temp = [];
		if(type == 'new') {
			temp = angular.copy($scope.allCity[$scope.newTeaItem.select.province]);
		} else if(type == 'edit') {
			temp = angular.copy($scope.allCity[$scope.modTeaItem.select.province]);
		}
		var cityList = [];
		for(var i in temp) {
			cityList.push(i);
		}
		if (type == 'new') {
			$scope.newTeaItem.cityList = cityList;
			// $scope.newTeaItem.select.city = {};
			$scope.newTeaItem.select.city = "";
			$scope.newTeaItem.districtList = [];
			// $scope.newTeaItem.select.district = {};
			$scope.newTeaItem.select.district = ""; 
		} else if(type == 'edit') {
			$scope.modTeaItem.cityList = cityList;
			// $scope.modTeaItem.select.city = {};
			$scope.modTeaItem.select.city = "";
			$scope.modTeaItem.districtList = [];
			// $scope.modTeaItem.select.district = {};
			$scope.modTeaItem.select.district = "";
		}
	};
	// 选择城市
	$scope.selectCity = function(type) {
		var temp = [];
		if(type == 'new') {
			temp = angular.copy($scope.allCity[$scope.newTeaItem.select.province][$scope.newTeaItem.select.city]);
		} else if(type == 'edit') {
			temp = angular.copy($scope.allCity[$scope.modTeaItem.select.province][$scope.modTeaItem.select.city]);
		}
		var districtList = [];
		for(var i in temp) {
			districtList.push(temp[i]);
		}
		if (type == 'new') {
			$scope.newTeaItem.districtList = districtList;
			// $scope.newTeaItem.select.district = {};
			$scope.newTeaItem.select.district = "";
		} else if(type == 'edit') {
			$scope.modTeaItem.districtList = districtList;
			// $scope.modTeaItem.select.district = {};
			$scope.modTeaItem.select.district = "";
		}
	};
	// 选择区域
    $scope.selectDistrict = function(type) {

	};

    /**
     * 新增教师
     */
    $scope.addTea = function() {
    	// 1.姓名
    	$scope.watchName('new');
    	// 2.办公电话
    	$scope.watchTel('new');
    	// 3.手机
		$scope.watchMobile('new');
		// 4.email
		$scope.watchEmail('new');
		// 5.学校
		$scope.watchSchool('new');
		// 6.紧急联系人
		$scope.watchContact('new');
		// 7.紧急联系人联系方式
		$scope.watchContactTel('new');
		// 8.详细地址
		$scope.watchAddress('new');
		// 9.家庭联系方式
		$scope.watchHomeTel('new');
		// 10.家庭邮政
		$scope.watchHomePostcode('new');
		// 11.员工编号
		$scope.watchCode('new');
    	
    	// 判断是否可以提交
    	if(!Tools.reg.isNull($scope.newTeaItem.warn.name) || !Tools.reg.isNull($scope.newTeaItem.warn.tel) || !Tools.reg.isNull($scope.newTeaItem.warn.mobile)) {
    		alert("请修改表单");
    		return;
    	}
    	if(!Tools.reg.isNull($scope.newTeaItem.warn.email) || !Tools.reg.isNull($scope.newTeaItem.warn.school) || !Tools.reg.isNull($scope.newTeaItem.warn.contact)) {
    		alert("请修改表单");
    		return;
    	}
    	if(!Tools.reg.isNull($scope.newTeaItem.warn.contactTel) || !Tools.reg.isNull($scope.newTeaItem.warn.address) || !Tools.reg.isNull($scope.newTeaItem.warn.homeTel)) {
    		alert("请修改表单");
    		return;
    	}
    	if(!Tools.reg.isNull($scope.newTeaItem.warn.homePostcode) || !Tools.reg.isNull($scope.newTeaItem.warn.code)) {
    		alert("请修改表单");
    		return;
    	}
    	
    	// 状态
    	var status = 0;
    	if($scope.newTeaItem.select.status == null) {
    		status = 0;
    	} else if(!$scope.newTeaItem.select.status.id) {
    		status = 0;
    	} else {
    		status = $scope.newTeaItem.select.status.id;
    	}
    	// 职务
    	var title = "";
    	if($scope.newTeaItem.select.title == null) {
    		title = "";
    	} else if(!$scope.newTeaItem.select.title.name) {
    		title = "";
    	} else {
    		title = $scope.newTeaItem.select.title.name;
    	}
    	// 国籍
    	var countryId = 0;
    	if($scope.newTeaItem.select.countryId == null) {
    		countryId = 0;
    	} else if(!$scope.newTeaItem.select.countryId.id) {
    		countryId = 0;
    	} else {
    		countryId = $scope.newTeaItem.select.countryId.id;
    	}
    	// 学历
    	var education = 0;
    	if($scope.newTeaItem.select.education == null) {
    		education = 0;
    	} else if(!$scope.newTeaItem.select.education.id) {
    		education = 0;
    	} else {
    		education = $scope.newTeaItem.select.education.id;
    	}
    	// 婚姻
    	var maritalStatus = 0;
    	if($scope.newTeaItem.select.maritalStatus == null) {
    		maritalStatus = 0;
    	} else if(!$scope.newTeaItem.select.maritalStatus.id) {
    		maritalStatus = 0;
    	} else {
    		maritalStatus = $scope.newTeaItem.select.maritalStatus.id;
    	}
    	// 性别
    	var sex = 0;
    	if($scope.newTeaItem.select.sex == null) {
    		sex = 0;
    	} else if(!$scope.newTeaItem.select.sex.id) {
    		sex = 0;
    	} else {
    		sex = $scope.newTeaItem.select.sex.id;
    	}
    	// 关联用户
    	var userId = 0;
    	if($scope.newTeaItem.select.userId == null) {
    		userId = 0;
    	} else if(!$scope.newTeaItem.select.userId.userId) {
    		userId = 0;
    	} else {
    		userId = $scope.newTeaItem.select.userId.userId;
    	}
    	// 省
    	var province = "";
    	if(typeof $scope.newTeaItem.select.province != "string") {
    		$scope.newTeaItem.select.province = "";
    	}

    	// 市
    	var city = "";
    	if(typeof $scope.newTeaItem.select.city != "string") {
    		$scope.newTeaItem.select.city = "";
    	}
    	// 区
    	var district = "";
    	if(typeof $scope.newTeaItem.select.district != "string") {
    		$scope.newTeaItem.select.district = "";
    	}
    	var data = {
    		address: $scope.newTeaItem.address,
			birthday: $scope.newTeaItem.birthday,
			code: $scope.newTeaItem.code,
			contact: $scope.newTeaItem.contact,
			contactTel: $scope.newTeaItem.contactTel,
			countryId: countryId,
			education: education,
			email: $scope.newTeaItem.email,
			homePostcode: $scope.newTeaItem.homePostcode,
			homeTel: $scope.newTeaItem.homeTel,
			joinedDate: $scope.newTeaItem.joinedDate,
			maritalStatus: maritalStatus,
			mobile: $scope.newTeaItem.mobile,
			name: $scope.newTeaItem.name,
			school: $scope.newTeaItem.school,
			sex: sex,
			status: status,
			tel: $scope.newTeaItem.tel,
			title: title,
			userId: userId,
			province: $scope.newTeaItem.select.province,
			city: $scope.newTeaItem.select.city,
			district: $scope.newTeaItem.select.district
    	};
    	commonSrv.addTeacher(data, function(result) {
    		if(result.status == 0) {
    			$scope.msg = "新增成功";
    			$scope.visible = true;
    			$scope.newTeaItem = {};
    			$('#addTeaModel').modal('hide');
    			$scope.getTeacherList(1);
    		}
    	}, function(result) {
    		if(result.status == 1) {
    			alert(result.msg);
    		}
    	}, function() {
    		$scope.$apply();
    	});
    };
    /**
     * 获取修改教师表单信息
     * @return {[type]} [description]
     */
    $scope.getTeaEditForm = function() {

    };

    // 删除
    /**
     * 打开删除教师弹层
     * @param  {[type]} item [description]
     */
    $scope.openDel = function(item) {
    	$scope.delTeaItem = item;
    	$('#delTeaModel').modal('show');
    };
    /**
     * 删除教师
     */
    $scope.delTea = function() {
    	var data = {
    		teacherId: $scope.delTeaItem.teacherId
    	};
    	commonSrv.delTeacher(data, function(result) {
    		if(result.status == 0) {
    			$scope.msg = "删除成功";
    			$scope.visible = true;
    			$scope.getTeacherList($scope.curPage);
    		}
    	}, function(result) {
    		if(result.status == 1) {
    			alert(result.msg);
    		}
    	}, function() {
    		$("#delTeaModel").modal('hide');
    		$scope.delTeaModel = {};
    		$scope.$apply();
    	});
    };

    // 修改
    /**
     * 打开修改教师弹层
     * @param  {[type]} item [description]
     */
	$scope.openEdit = function(item) {
		var data = {
			teacherId: item.teacherId
		};
		commonSrv.getTeacherEditForm(data, function(result) {
			if(result.status == 0) {
				$scope.modTeaItem = result.data;
				$scope.modTeaItem.teacherId = item.teacherId;

				$.ajax({
    				// url: '/ta/CityCtrl/getAllCity.do',
    				url: '../common/libs/allCity.json',
    				data: {},
    				success: function(result) {
    					if (typeof result == 'string') {
    						result = JSON.parse(result);
    					}
						//设置下来列表默认选项 
						// 1.职务
						var title = $scope.modTeaItem.teacher.title;
						for(var i in $scope.modTeaItem.titleList) {
							if(title == $scope.modTeaItem.titleList[i].name) {
								title = $scope.modTeaItem.titleList[i];
								break;
							}
						}
						// 2.关联用户名
						var userId = $scope.modTeaItem.teacher.userId;
						for(var i in $scope.modTeaItem.userList) {
							if(userId == $scope.modTeaItem.userList[i].userId) {
								userId = $scope.modTeaItem.userList[i];
								break;
							}
						}
						// 3.状态
						var status = $scope.modTeaItem.teacher.status;
						for(var i in $scope.modTeaItem.statusList) {
							if(status == $scope.modTeaItem.statusList[i].id) {
								status = $scope.modTeaItem.statusList[i];
								break;
							}
						}
						// 4.入职日期
						var joinedDate = moment($scope.modTeaItem.teacher.joinedDate).toDate();
						$("#joinedDate_mod").datepicker({
							format: "yyyy-mm-dd",
							language: 'zh-CN'
						});
						$("#joinedDate_mod").datepicker("setDate", joinedDate);
						// 5.性别
						var sex = $scope.modTeaItem.teacher.sex;
						for(var i in $scope.modTeaItem.sexList) {
							if(sex == $scope.modTeaItem.sexList[i].id) {
								sex = $scope.modTeaItem.sexList[i];
								break;
							}
						}
						// 6.生日
						var birthday = moment($scope.modTeaItem.teacher.birthday).toDate();
						$("#birthday_mod").datepicker({
							format: "yyyy-mm-dd",
							language: 'zh-CN'
						});
						$("#joinedDate_mod").datepicker("setDate", birthday);
						
						// 7.国籍
						var countryId = $scope.modTeaItem.teacher.countryId;
						for(var i in $scope.modTeaItem.countryList) {
							if(countryId == $scope.modTeaItem.countryList[i].id) {
								countryId = $scope.modTeaItem.countryList[i];
								break;
							}
						}
						// 8.婚姻状态
						var maritalStatus = $scope.modTeaItem.teacher.maritalStatus;
						for(var i in $scope.modTeaItem.maritalStatusList) {
							if(maritalStatus == $scope.modTeaItem.maritalStatusList[i].id) {
								maritalStatus = $scope.modTeaItem.maritalStatusList[i];
								break;
							}
						}
						// 9.学历
						var education = $scope.modTeaItem.teacher.education;
						for(var i in $scope.modTeaItem.educationList) {
							if(education == $scope.modTeaItem.educationList[i].id) {
								education = $scope.modTeaItem.educationList[i];
								break;
							}
						}
						// 省市区
    					$scope.allCity = result;
						// 10.省
						var provinceList = [];
    					for(var i in $scope.allCity) {
    						provinceList.push(i);
    					}
    					var province = $scope.modTeaItem.teacher.province;
    					$scope.modTeaItem.provinceList = provinceList;
    					for(var i in $scope.modTeaItem.provinceList) {
    						if(province == $scope.modTeaItem.provinceList[i]) {
    							province = $scope.modTeaItem.provinceList[i];
    							break;
    						}
    					}
						
						// 11.市
						var cityListTemp = [];
						if(province && province != '') {
							cityListTemp = angular.copy($scope.allCity[province]);
						}
						var cityList = [];
						// 这里的cityListTemp是对象不是数组，注意！！！
						if(cityListTemp && !(cityListTemp instanceof Array)) {
							for(var i in cityListTemp) {
								cityList.push(i);
							}
						}
						var city = $scope.modTeaItem.teacher.city;
						$scope.modTeaItem.cityList = cityList;
						if(cityList && cityList.length > 0) {
							for(var i in $scope.modTeaItem.cityList) {
	    						if(city == $scope.modTeaItem.cityList[i]) {
	    							city = $scope.modTeaItem.cityList[i];
	    							break;
	    						}
	    					}
    					}
						
						// 12.区
		    			var districtList = [];
		    			if(city && city != '') {
		    				districtList = angular.copy($scope.allCity[province][city]);
		    			}
						var district = $scope.modTeaItem.teacher.district;
						$scope.modTeaItem.districtList = districtList;
						if(districtList && districtList.length >0) {
							for(var i in $scope.modTeaItem.districtList) {
	    						if(district == $scope.modTeaItem.districtList[i]) {
	    							district = $scope.modTeaItem.districtList[i];
	    							break;
	    						}
	    					}
						}
		    			// 已选择
		    			$scope.modTeaItem.select = {
		    				title: title,
		    				userId: userId,
		    				status: status,
		    				sex: sex,
		    				countryId: countryId,
		    				maritalStatus: maritalStatus,
		    				education: education,
		    				province: province,
		    				city: city,
		    				district: district
		    			};
		    			// 警告
		    			$scope.modTeaItem.warn = {
		    				address: "",
							birthday: "",
							code: "",
							contact: "",
							contactTel: "",
							countryId: "",
							education: "",
							email: "",
							homePostcode: "",
							homeTel: "",
							joinedDate: "",
							maritalStatus: "",
							mobile: "",
							name: "",
							school: "",
							sex: "",
							status: "",
							tel: "",
							title: "",
							userId: ""
		    			};
						$('#editTeaModel').modal({backdrop: 'static', keyboard: false, show: true});
    				},fail: function(result) {
	    				if(result.status == 1) {
	    					alert("获取城市下拉列表失败");
	    				}
	    			}
	    		}).always(function() {
	    			$scope.$apply();
	    		});
			}
		}, function(result) {
			if(result.status == 1) {
				alert(result.msg);
			}
		}, function() {
			$scope.$apply();
		})
    };
    /**
     * 修改教师
     */
    $scope.editTea = function() {
    	// 1.姓名
    	$scope.watchName('edit');
    	// 2.办公电话
    	$scope.watchTel('edit');
    	// 3.手机
		$scope.watchMobile('edit');
		// 4.email
		$scope.watchEmail('edit');
		// 5.学校
		$scope.watchSchool('edit');
		// 6.紧急联系人
		$scope.watchContact('edit');
		// 7.紧急联系人联系方式
		$scope.watchContactTel('edit');
		// 8.详细地址
		$scope.watchAddress('edit');
		// 9.家庭联系方式
		$scope.watchHomeTel('edit');
		// 10.家庭邮政
		$scope.watchHomePostcode('edit');
		// 11.员工编号
		$scope.watchCode('edit');

		// 判断是否可以提交
    	if(!Tools.reg.isNull($scope.modTeaItem.warn.name) || !Tools.reg.isNull($scope.modTeaItem.warn.tel) || !Tools.reg.isNull($scope.modTeaItem.warn.mobile)) {
    		alert("请修改表单");
    		return;
    	}
    	if(!Tools.reg.isNull($scope.modTeaItem.warn.email) || !Tools.reg.isNull($scope.modTeaItem.warn.school) || !Tools.reg.isNull($scope.modTeaItem.warn.contact)) {
    		alert("请修改表单");
    		return;
    	}
    	if(!Tools.reg.isNull($scope.modTeaItem.warn.contactTel) || !Tools.reg.isNull($scope.modTeaItem.warn.address) || !Tools.reg.isNull($scope.modTeaItem.warn.homeTel)) {
    		alert("请修改表单");
    		return;
    	}
    	if(!Tools.reg.isNull($scope.modTeaItem.warn.homePostcode) || !Tools.reg.isNull($scope.modTeaItem.warn.code)) {
    		alert("请修改表单");
    		return;
    	}

    	// 状态
    	var status = 0;
    	if($scope.modTeaItem.select.status == null) {
    		status = 0;
    	} else if(!$scope.modTeaItem.select.status.id) {
    		status = 0;
    	} else {
    		status = $scope.modTeaItem.select.status.id;
    	}
    	// 职务
    	var title = "";
    	if($scope.modTeaItem.select.title == null) {
    		title = "";
    	} else if(!$scope.modTeaItem.select.title.name) {
    		title = "";
    	} else {
    		title = $scope.modTeaItem.select.title.name;
    	}
    	// 国籍
    	var countryId = 0;
    	if($scope.modTeaItem.select.countryId == null) {
    		countryId = 0;
    	} else if(!$scope.modTeaItem.select.countryId.id) {
    		countryId = 0;
    	} else {
    		countryId = $scope.modTeaItem.select.countryId.id;
    	}
    	// 学历
    	var education = 0;
    	if($scope.modTeaItem.select.education == null) {
    		education = 0;
    	} else if(!$scope.modTeaItem.select.education.id) {
    		education = 0;
    	} else {
    		education = $scope.modTeaItem.select.education.id;
    	}   	
    	// 婚姻
    	var maritalStatus = 0;
    	if($scope.modTeaItem.select.maritalStatus == null) {
    		maritalStatus = 0;
    	} else if(!$scope.modTeaItem.select.maritalStatus.id) {
    		maritalStatus = 0;
    	} else {
    		maritalStatus = $scope.modTeaItem.select.maritalStatus.id;
    	}
    	// 性别
    	var sex = 0;
    	if($scope.modTeaItem.select.sex == null) {
    		sex = 0;
    	} else if(!$scope.modTeaItem.select.sex.id) {
    		sex = 0;
    	} else {
    		sex = $scope.modTeaItem.select.sex.id;
    	}
    	// 关联用户
    	var userId = 0;
    	if($scope.modTeaItem.select.userId == null) {
    		userId = 0;
    	} else if(!$scope.modTeaItem.select.userId.userId) {
    		userId = 0;
    	} else {
    		userId = $scope.modTeaItem.select.userId.userId;
    	}
    	// 省
    	if(typeof $scope.modTeaItem.select.province != "string") {
    		$scope.modTeaItem.select.province = "";
    	}
    	// 市
    	if(typeof $scope.modTeaItem.select.city != "string") {
    		$scope.modTeaItem.select.city = "";
    	}
    	// 区
    	if(typeof $scope.modTeaItem.select.district != "string") {
    		$scope.modTeaItem.select.district = "";
    	}

    	var data = {
    		address: $scope.modTeaItem.teacher.address,
			birthday: $scope.modTeaItem.teacher.birthday,
			code: $scope.modTeaItem.teacher.code,
			contact: $scope.modTeaItem.teacher.contact,
			contactTel: $scope.modTeaItem.teacher.contactTel,
			countryId: countryId,
			education: education,
			email: $scope.modTeaItem.teacher.email,
			homePostcode: $scope.modTeaItem.teacher.homePostcode,
			homeTel: $scope.modTeaItem.teacher.homeTel,
			joinedDate: $scope.modTeaItem.teacher.joinedDate,
			maritalStatus: maritalStatus,
			mobile: $scope.modTeaItem.teacher.mobile,
			name: $scope.modTeaItem.teacher.name,
			school: $scope.modTeaItem.teacher.school,
			sex: sex,
			status: status,
			tel: $scope.modTeaItem.teacher.tel,
			title: title,
			userId: userId,
			province: $scope.modTeaItem.select.province,
			city: $scope.modTeaItem.select.city,
			district: $scope.modTeaItem.select.district,
			teacherId: $scope.modTeaItem.teacherId
    	};

		commonSrv.editTeacher(data, function(result) {
			if(result.status == 0) {
				$scope.msg = "修改成功";
				$scope.visible = true;
				$("#editTeaModel").modal('hide');
				$scope.getTeacherList($scope.curPage);
			}
		}, function(result) {
			if(result.status == 1) {
				alert(result.msg);
			}
		}, function() {
			$scope.$apply();
		})
    };
    /**
     * 获取修改教师表单信息
     * @return {[type]} [description]
     */
    $scope.getTeaEditForm = function() {
    	
    };

    // 验证
    // 1.用户名--2-16个字符(包含：中文、英文、数字)
	$scope.watchName = function (type) {
		var nullWarn = "姓名不能为空";
		var formatWarn = "请输入长度为2-16个字符(中文、英文、数字)";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.name)) {
				$scope.newTeaItem.warn.name = nullWarn;
			} else {
				if(!Tools.reg.name($scope.newTeaItem.name)) {
					$scope.newTeaItem.warn.name = formatWarn;
				} else {
					$scope.newTeaItem.warn.name = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.name)) {
				$scope.modTeaItem.warn.name = nullWarn;
			} else {
				if(!Tools.reg.name($scope.modTeaItem.teacher.name)) {
					$scope.modTeaItem.warn.name = formatWarn;
				} else {
					$scope.modTeaItem.warn.name = "";
				}
			}
		}
	};
	// 2.办公电话
	$scope.watchTel = function (type) {
		var formatWarn = "请输入正确的电话号码";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.tel)) {
				$scope.newTeaItem.warn.tel = "";
			} else {
				if(!Tools.reg.tel($scope.newTeaItem.tel)) {
					$scope.newTeaItem.warn.tel = formatWarn;
				} else {
					$scope.newTeaItem.warn.tel = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.tel)) {
				$scope.modTeaItem.warn.tel = "";
			} else {
				if(!Tools.reg.tel($scope.modTeaItem.teacher.tel)) {
					$scope.modTeaItem.warn.tel = formatWarn;
				} else {
					$scope.modTeaItem.warn.tel = "";
				}
			}
		}
	};
	// 3.手机
	$scope.watchMobile = function (type) {
		var formatWarn = "请输入正确的手机号码";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.mobile)) {
				$scope.newTeaItem.warn.mobile = "";
			} else {
				if(!Tools.reg.mobile($scope.newTeaItem.mobile)) {
					$scope.newTeaItem.warn.mobile = formatWarn;
				} else {
					$scope.newTeaItem.warn.mobile = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.mobile)) {
				$scope.modTeaItem.warn.mobile = "";
			} else {
				if(!Tools.reg.mobile($scope.modTeaItem.teacher.mobile)) {
					$scope.modTeaItem.warn.mobile = formatWarn;
				} else {
					$scope.modTeaItem.warn.mobile = "";
				}
			}
		}
	};
	// 4.电子邮件
	$scope.watchEmail = function (type) {
		var formatWarn = "请输入正确的电子邮件";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.email)) {
				$scope.newTeaItem.warn.email = "";
			} else {
				if(!Tools.reg.email($scope.newTeaItem.email)) {
					$scope.newTeaItem.warn.email = formatWarn;
				} else {
					$scope.newTeaItem.warn.email = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.email)) {
				$scope.modTeaItem.warn.email = "";
			} else {
				if(!Tools.reg.email($scope.modTeaItem.teacher.email)) {
					$scope.modTeaItem.warn.email = formatWarn;
				} else {
					$scope.modTeaItem.warn.email = "";
				}
			}
		}
	};
	// 5.毕业院校
	$scope.watchSchool = function (type) {
		var formatWarn = "最多输入20个字符";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.school)) {
				$scope.newTeaItem.warn.school = "";
			} else {
				if($scope.newTeaItem.school.length > 20) {
					$scope.newTeaItem.warn.school = formatWarn;
				} else {
					$scope.newTeaItem.warn.school = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.school)) {
				$scope.modTeaItem.warn.school = "";
			} else {
				if($scope.modTeaItem.teacher.school.length > 20) {
					$scope.modTeaItem.warn.school = formatWarn;
				} else {
					$scope.modTeaItem.warn.school = "";
				}
			}
		}
	};
	// 6.紧急联系人
	$scope.watchContact = function (type) {
		var formatWarn = "请输入正确的紧急联系人(长度为2-16个字符)";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.contact)) {
				$scope.newTeaItem.warn.contact = "";
			} else {
				if(!Tools.reg.name($scope.newTeaItem.contact)) {
					$scope.newTeaItem.warn.contact = formatWarn;
				} else {
					$scope.newTeaItem.warn.contact = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.contact)) {
				$scope.modTeaItem.warn.contact = "";
			} else {
				if(!Tools.reg.name($scope.modTeaItem.teacher.contact)) {
					$scope.modTeaItem.warn.contact = formatWarn;
				} else {
					$scope.modTeaItem.warn.contact = "";
				}
			}
		}
	};
	// 7.紧急联系人
	$scope.watchContactTel = function (type) {
		var formatWarn = "请输入正确的手机号码";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.contactTel)) {
				$scope.newTeaItem.warn.contactTel = "";
			} else {
				if(!Tools.reg.mobile($scope.newTeaItem.contactTel)) {
					$scope.newTeaItem.warn.contactTel = formatWarn;
				} else {
					$scope.newTeaItem.warn.contactTel = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.contactTel)) {
				$scope.modTeaItem.warn.contactTel = "";
			} else {
				if(!Tools.reg.mobile($scope.modTeaItem.teacher.contactTel)) {
					$scope.modTeaItem.warn.contactTel = formatWarn;
				} else {
					$scope.modTeaItem.warn.contactTel = "";
				}
			}
		}
	};
	// 8.家庭地址-详细地址
	$scope.watchAddress = function (type) {
		var formatWarn = "最多输入40个字符";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.address)) {
				$scope.newTeaItem.warn.address = "";
			} else {
				if($scope.newTeaItem.address.length > 40) {
					$scope.newTeaItem.warn.address = formatWarn;
				} else {
					$scope.newTeaItem.warn.address = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.address)) {
				$scope.modTeaItem.warn.address = "";
			} else {
				if($scope.modTeaItem.teacher.address.length > 40) {
					$scope.modTeaItem.warn.address = formatWarn;
				} else {
					$scope.modTeaItem.warn.address = "";
				}
			}
		}
	};
	// 9.家庭电话
	$scope.watchHomeTel = function (type) {
		var formatWarn = "请输入正确的电话号码";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.homeTel)) {
				$scope.newTeaItem.warn.homeTel = "";
			} else {
				if(!Tools.reg.tel($scope.newTeaItem.homeTel)) {
					$scope.newTeaItem.warn.homeTel = formatWarn;
				} else {
					$scope.newTeaItem.warn.homeTel = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.homeTel)) {
				$scope.modTeaItem.warn.homeTel = "";
			} else {
				if(!Tools.reg.tel($scope.modTeaItem.teacher.homeTel)) {
					$scope.modTeaItem.warn.homeTel = formatWarn;
				} else {
					$scope.modTeaItem.warn.homeTel = "";
				}
			}
		}
	};
	// 10.家庭邮编
	$scope.watchHomePostcode = function (type) {
		var formatWarn = "请输入正确的邮政编码";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.homePostcode)) {
				$scope.newTeaItem.warn.homePostcode = "";
			} else {
				if(!Tools.reg.zip($scope.newTeaItem.homePostcode)) {
					$scope.newTeaItem.warn.homePostcode = formatWarn;
				} else {
					$scope.newTeaItem.warn.homePostcode = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.homePostcode)) {
				$scope.modTeaItem.warn.homePostcode = "";
			} else {
				if(!Tools.reg.zip($scope.modTeaItem.teacher.homePostcode)) {
					$scope.modTeaItem.warn.homePostcode = formatWarn;
				} else {
					$scope.modTeaItem.warn.homePostcode = "";
				}
			}
		}
	};
	// 11.员工编号
	$scope.watchCode = function (type) {
		var formatWarn = "最多输入30个字符";
		if(type == 'new') {
			if(Tools.reg.isNull($scope.newTeaItem.code)) {
				$scope.newTeaItem.warn.code = "";
			} else {
				if($scope.newTeaItem.code.length > 30) {
					$scope.newTeaItem.warn.code = formatWarn;
				} else {
					$scope.newTeaItem.warn.code = "";
				}
			}
		} else if(type == 'edit') {
			if(Tools.reg.isNull($scope.modTeaItem.teacher.code)) {
				$scope.modTeaItem.warn.code = "";
			} else {
				if($scope.modTeaItem.teacher.code.length > 30) {
					$scope.modTeaItem.warn.code = formatWarn;
				} else {
					$scope.modTeaItem.warn.code = "";
				}
			}
		}
	};
	// 初始化
	function init() {
		$scope.getTeacherList(1);
		$(document).ready(function() {
			// console.log($rootScope.secondType);
		});
	}
	init();
}]);